package com.company.ASM;

import org.springframework.asm.ClassReader;
import org.springframework.asm.ClassVisitor;
import org.springframework.asm.FieldVisitor;
import org.springframework.asm.MethodVisitor;

import java.io.IOException;


public class ClassPrinter extends ClassVisitor {


    public ClassPrinter(int api) {
        super(api);
    }

    public ClassPrinter(int api, ClassVisitor classVisitor) {
        super(api, classVisitor);
    }


    @Override
    public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
        System.out.println(" " + name);
        return super.visitField(access, name, descriptor, signature, value);

    }

    @Override
    public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
        System.out.println(" " + name + "()");
        return super.visitMethod(access, name, descriptor, signature, exceptions);
    }

    @Override
    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
        System.out.println("name=" + name + "extends" + superName + "{");
        super.visit(version, access, name, signature, superName, interfaces);
    }

    @Override
    public void visitEnd() {

        System.out.println(" " + "}");
        super.visitEnd();
    }

    public static void main(String[] args) throws IOException {
        ClassPrinter cp = new ClassPrinter(589824);
        ClassReader cr = new ClassReader(ClassPrinter.class.getClassLoader().getResourceAsStream("java.lang.Runnable"));
        cr.accept(cp, 0);
    }
}
